home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kselect.h.z / kselect.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  3.8 KB  |  153 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.     Boston, MA 02111-1307, USA.
  18. */
  19. //-----------------------------------------------------------------------------
  20. // Selector widgets for KDE Color Selector, but probably useful for other
  21. // stuff also.
  22.  
  23. #ifndef __KSELECT_H__
  24. #define __KSELECT_H__
  25.  
  26. #include <qdialog.h>
  27. #include <qframe.h>
  28. #include <qrangect.h>
  29. #include <qlined.h>
  30. #include <qpixmap.h>
  31.  
  32. /// 2D value selector.
  33. /** 2D value selector.
  34.   The contents of the selector are drawn by derived class.
  35.   */
  36. class KXYSelector : public QWidget
  37. {
  38.   Q_OBJECT
  39. public:
  40.   KXYSelector( QWidget *parent = 0L, const char *name = 0L );
  41.  
  42.   void setValues( int _xPos, int _yPos );
  43.   void setRange( int _minX, int _minY, int _maxX, int _maxY );
  44.  
  45.   int xValue()    {    return xPos; }
  46.   int yValue()    {    return yPos; }
  47.  
  48.   QRect contentsRect();
  49.  
  50.   signals:
  51.   void valueChanged( int _x, int _y );
  52.  
  53. protected:
  54.   virtual void paintEvent( QPaintEvent *e );
  55.  
  56.   /// Draw contents
  57.   /** Override this function to draw the contents of the widget.
  58.     Draw within contentsRect() only
  59.     */
  60.   virtual void drawContents( QPainter * ) {}
  61.  
  62.   virtual void mousePressEvent( QMouseEvent *e );
  63.   virtual void mouseMoveEvent( QMouseEvent *e );
  64.  
  65. private:
  66.   void setPosition( int xp, int yp );
  67.   void drawCursor( QPainter &painter, int xp, int yp );
  68.  
  69. protected:
  70.   int px;
  71.   int py;
  72.   int xPos;
  73.   int yPos;
  74.   int minX;
  75.   int maxX;
  76.   int minY;
  77.   int maxY;
  78.   QPixmap store;
  79. };
  80.  
  81. /// 1D value selector
  82. /** 1D value selector with contents drawn by derived class.
  83.   See KColorDialog for example.
  84.  */
  85. class KSelector : public QWidget, public QRangeControl
  86. {
  87.   Q_OBJECT
  88. public:
  89.   enum Orientation { Horizontal, Vertical };
  90.  
  91.   KSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
  92.  
  93.   Orientation orientation() const
  94.   {    return _orientation; }
  95.  
  96.   QRect contentsRect();
  97.  
  98.   void setIndent( bool i )
  99.   {    _indent = i; }
  100.   bool indent() const
  101.   {    return _indent; }
  102.  
  103.   signals:
  104.   void valueChanged( int value );
  105.  
  106. protected:
  107.   /**
  108.     Override this function to draw the contents of the control.
  109.     Draw only within contentsRect().
  110.     */
  111.   virtual void drawContents( QPainter * ) {}
  112.  
  113.   virtual void valueChange();
  114.   virtual void drawArrow( QPainter &painter, bool show, const QPoint &pos );
  115.  
  116. private:
  117.   QPoint calcArrowPos( int val );
  118.   void moveArrow( const QPoint &pos );
  119.  
  120.   virtual void paintEvent( QPaintEvent * );
  121.   virtual void mousePressEvent( QMouseEvent *e );
  122.   virtual void mouseMoveEvent( QMouseEvent *e );
  123.  
  124. protected:
  125.   Orientation _orientation;
  126.   bool _indent;
  127. };
  128.  
  129. //-----------------------------------------------------------------------------
  130.  
  131. class KGradientSelector : public KSelector
  132. {
  133.   Q_OBJECT
  134. public:
  135.   KGradientSelector( Orientation o, QWidget *parent = 0L,
  136.                      const char *name = 0L );
  137.  
  138.   void setColors( const QColor &col1, const QColor &col2 )
  139.   {    color1 = col1; color2 = col2; }
  140.   void setText( const char *t1, const char *t2 )
  141.   {    text1 = t1; text2 = t2; }
  142.  
  143. protected:
  144.   virtual void drawContents( QPainter * );
  145.  
  146. protected:
  147.   QColor color1, color2;
  148.   QString text1, text2;
  149. };
  150.  
  151. #endif        // __KSELECT_H__
  152.  
  153.